<!--创建专项活动评价-->
<template>
  <div class="wrapper-container">
    <el-form ref="form" class="my-form">
      <el-row class="single-row">
        <el-col :span="24">
          <el-row class="item-row">
            <el-col class="name-col" :span="6"> 学期</el-col>
            <el-col class="content-col" :span="18">
              <SelectItem
                :name="''"
                :value="tableData.term"
                @change="
                  (e) => {
                    tableData.term = e;
                  }
                "
                :xqList="xqList"
              ></SelectItem>
            </el-col>
          </el-row>
        </el-col>
      </el-row>
      <el-row class="single-row">
        <el-col :span="24">
          <el-row class="item-row">
            <el-col class="name-col" :span="6"> 评价活动名称</el-col>
            <el-col class="content-col" :span="18">
              <el-input
                v-model="tableData.evalprojectname"
                style="width: 50%"
                size="small"
              ></el-input>
            </el-col>
          </el-row>
        </el-col>
      </el-row>
      <el-row class="single-row">
        <el-col :span="12">
          <el-row class="item-row">
            <el-col class="name-col" :span="12"> 开始时间</el-col>
            <el-col class="content-col" :span="12">
              <el-date-picker
                v-model="tableData.begindate"
                type="datetime"
                placeholder="选择开始时间"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="width: 50%"
              >
              </el-date-picker>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="12">
          <el-row class="item-row">
            <el-col class="name-col" :span="12"> 结束时间</el-col>
            <el-col class="content-col" :span="12">
              <el-date-picker
                v-model="tableData.enddate"
                type="datetime"
                placeholder="选择结束时间"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="width: 50%"
              >
              </el-date-picker>
            </el-col>
          </el-row>
        </el-col>
      </el-row>
      <el-row class="single-row">
        <el-col :span="24">
          <el-row class="item-row">
            <el-col class="name-col" :span="6"> 指标体系</el-col>
            <el-col class="content-col" :span="18">
              <SelectItem style="width: 200px"
                          :name="''"
                          :value="guidename"
                          @change="
                  (e) => {
                    guidename = e;
                  }
                "
                          :xqList="systemList"
              ></SelectItem>
            </el-col>
          </el-row>
        </el-col>
      </el-row>
      <el-row class="single-row">
        <el-col :span="24">
          <el-row class="item-row">
            <el-col class="name-col" :span="6"> 各个等级比例限制</el-col>
            <el-col class="content-col" :span="18">
              <!--              <el-input type="text" style="width: 110px" v-for="(item,index) in this.proportionalList " :key='index'-->
              <!--                        v-model="baseInfo['level'+item]"-->
              <!--                        size="mini">-->
              <!--              </el-input>-->


              <InputItem v-for="(item,index) in this.proportionalList " :key='index'
                         :name="item"
                         :value="propor['level'+index]"
                         @input="
                                (e) => {
                                  propor['level'+index] = e;
                                }
                              "
                         :endText="'%'"
              ></InputItem>
            </el-col>
          </el-row>
        </el-col>
      </el-row>
      <el-row class="single-row">
        <el-col :span="24">
          <el-row class="item-row" style="height: 115px">
            <el-col class="name-col" style="height: 100%" :span="6">
              评价说明
            </el-col>
            <el-col class="content-col" style="height: 100%" :span="18">
              <el-input
                style="width: 50%; margin: 10px 0; max-height: 90px"
                type="textarea"
                placeholder="请输入内容"
                v-model="tableData.teaching"
              >
              </el-input>
            </el-col>
          </el-row>
        </el-col>
      </el-row>
    </el-form>
    <div class="table-container">
      <span class="name-col" style="background-color: white">评价关系设置</span>
      <el-table
        :data="tablelist"
        border
        class="table-data"
        row-class-name="row-class"
        cell-class-name="cell-class"
        header-row-class-name="header-row-class"
        header-cell-class-name="header-cell-class"
      >
        <el-table-column prop="task" label="承担任务" align="center">
        </el-table-column>
        <el-table-column prop="numName" label="教员" align="center">

          <template slot-scope="scope">
            <SelectItem style="width: 200px"
                        :name="''"
                        :value="scope.row.xm"
                        @change="
                  (e) => {
                    scope.row.xm = e;
                  }
                "
                        :xqList="teacherList"
            ></SelectItem>
          </template>
        </el-table-column>
        <el-table-column prop="teachingClassName" label="评价教学班" align="center">
          <template slot-scope="scope">
            <SelectItem style="width: 200px"
                        :name="''"
                        :value="scope.row.teachingClassName"
                        @change="
                  (e) => {
                    scope.row.teachingClassName = e;
                  }
                "
                        :xqList="classList"
            ></SelectItem>
          </template>
        </el-table-column>
        <el-table-column prop="scoreNature" label="操作" align="center">
          <template slot-scope="scope">
            <div
              style="
                display: flex;
                padding-left: 10px;
                justify-content: space-around;
              "
            >
              <ButtonItem
                @click="addClick(scope.$index)"
                :name="'增加'"
                :link="''"
                :icon="'el-icon-circle-plus-outline'"
                :buttonColor="'yellow'"
              ></ButtonItem>

              <ButtonItem
                @click="deleteClick(scope.$index)"
                :name="'删除'"
                :link="''"
                :icon="'el-icon-circle-close'"
                :buttonColor="'red'"
              ></ButtonItem>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div class="bottom-block">
      <div style="width: 300px; display: flex; justify-content: space-around">
        <ButtonItem
          :name="'保存'"
          :link="''"
          :icon="''"
          :buttonColor="'yellow'"
          @click="save"
        ></ButtonItem>

        <ButtonItem
          :name="'取消'"
          :link="''"
          :icon="''"
          :buttonColor="'red'"
          @click="Cancel"
        ></ButtonItem>
      </div>
    </div>
  </div>
</template>

<script>
import SelectItem from "../../../components/SelectItem.vue";
import InputItem from "../../../components/InputItem.vue";
import ButtonItem from "../../../components/ButtonItem.vue";
import {
  ByAllRankAndGuide,
  insert,
} from "@/api/evaluation/setActivityEvaluations";

import {teacherinfoSelectAll,teachingclassSelectAll} from "../../../api/evaluation/setActivityEvaluations";
import {pjevalprojectById} from "../../../api/teacher/admin";


export default {
  components: {
    SelectItem,
    InputItem,
    ButtonItem,
  },
  data() {
    return {
      tableData: {
        // guiderankoption: '',//各个等级比例
        teaching: '',//评教说明
        guidename: '',//指标项名称
        evalprojectname: '',//评价活动名称
        enddate: '',//结束时间
        begindate: '',//开始时间
        term: '2021春',//学期
        type : 3,

      },
      term: "2021春",
      xqList: [
        {
          value: "2021春",
          label: "2021春",
        },
        {
          value: "2020夏",
          label: "2020夏",
        },
      ],
      guidename: '',
      systemList: [
        {
          value: "2021春,2021春,2021春,2021春,2021春,2021春,2021春,2021春",
          label: "2021春",
        },
        {
          value: "a,b,c,d,e",
          label: "2020夏",
        },
      ],
      xm:'',
      teacherList: [
        {
          value:'',
          label:'',
        }
      ],

      teachingClassName:'',
      classList: [
        {
          value:'',
          label:'',
        }
      ],
      baseInfo: {
        courseName: "",
      },
      proportionalList: [],
      propor: {
        level1: "",
        level2: "",
        level3: "",
        level4: "",
        level5: "",
        level6: "",
        level7: "",
        level8: "",
        level9: "",
        level10: "",
        level0: ""
      },
      //关系设置
      tablelist: [
        {
          task: "任务1",
          xm: "",
          teachingClassName: "",
        },
      ],
      multipleSelection: [],
    };
  },
  watch: {
    guidename(val) {
      if (val) {
        this.proportionalList = this.systemList[val].guiderankoption.split(',')
      }
    },
  },
  mounted() {
    this.ByAllRankAndGuide()
    this.teacherinfoSelectAll()
    this.teachingclassSelectAll()
    this.pjevalprojectById()
  },
  methods: {
    //查询
    pjevalprojectById(){
      let id = {}
      id = this.$route.query.evalprojectid
      return new Promise(() => {
        pjevalprojectById(id).then(res => {
          this.tableData = res.data.data
        })
      })
    },

    teachingclassSelectAll(){
      return new Promise(() => {
        teachingclassSelectAll().then(res => {
          console.log("aaaaaaa")
          console.log(res.data.data)
          console.log("aaaaaaa")


          if (res.data.code === 200) {
            let data = res.data.data
            let arr = []
            for (const dataKey in data) {
              let obj = {...data[dataKey]}
              obj = {
                value: obj.teachingClassName+","+obj.id,//obj.guiderankoption
                label: obj.teachingClassName+","+obj.id,
                id: obj.id,
              }
              arr.push(obj)
              console.log(arr, 'arr教学班')
            }
            this.classList = arr
          }
        })
      })
    },
    teacherinfoSelectAll(){
      return new Promise(() => {
        teacherinfoSelectAll().then(res => {
          console.log("sssssssssss")
          console.log(res.data.data)
          console.log("sssssssssss")
          if (res.data.code === 200) {
            let datateach = res.data.data
            let arr = []
            for (const dataKey in datateach) {
              let obj = {...datateach[dataKey]}
              obj = {
                value: obj.xm+','+obj.id,//obj.guiderankoption
                label: obj.xm+','+obj.id,
                id:obj.id,
                xm:obj.xm,
              }
              arr.push(obj)
              console.log("111111111")
              console.log(obj)
              console.log("eeeee111111111")
            }
            this.teacherList = arr
          }
        })
      })
    },



    save() {
      let arre = [];

      for (let a = 0; a < this.tablelist.length; a++) {
        arre = this.tablelist[a].xm.split(",")
        for (let i = 0; i < arre.length; i++) {
          for (let t = i + 1; t < arre.length; t++) {
            this.tablelist[a].teachername = arre[i];
            this.tablelist[a].teacherid = arre[t];
          }
        }
      }
      console.log(this.tablelist)
      let arrs = [];

      for (let a = 0; a < this.tablelist.length; a++) {
        arrs = this.tablelist[a].teachingClassName.split(",")
        for (let i = 0; i < arrs.length; i++) {
          for (let t = i + 1; t < arrs.length; t++) {
            this.tablelist[a].studentclassname = arrs[i];
            this.tablelist[a].studentclassid = arrs[t];
          }
        }
      }
      console.log(this.tablelist)

      console.log(this.tablelist)
      console.log("eeeee11112222222222222222222222211111")
      this.tableData.pjEvalprojectObject = this.tablelist;
      let obj = this.tableData;


      console.log(obj);
      let arr = []
      if (!obj.term) {
        this.$message.error('学期未填写');
        return
      }
      if (!obj.evalprojectname) {
        this.$message.error('评价活动名称未填写');
        return
      }
      if (!obj.begindate) {
        this.$message.error('开始时间未填写');
        return
      }
      if (!obj.enddate) {
        this.$message.error('结束时间未填写');
        return
      }
      let guideid=this.systemList[this.guidename].guideid
      if (guideid) {
        obj.zhibiaoid = guideid
      } else {
        this.$message.error('指标项名称未填写');
      }
      for (let i = 0; i < this.proportionalList.length; i++) {
        if (this.propor["level" + i]) {
          let obj = this.proportionalList[i] + ':' + this.propor["level" + i]
          arr.push(obj)
        } else {
          this.$message.error('各个等级比例限制中有未填写项');
          return
        }
      }
      if (!obj.teaching) {
        this.$message.error('评教说明未填写');
        return
      }

      obj.type = 3

      obj.proportionallimit = arr.toString()
      return new Promise(() => {
        insert(obj).then(res => {
          console.log(res.status)
          if (res.status === 200) {
            let pathname = '/' + window.location.pathname.split('/')[1]
            this.$router.push(pathname + "/examination/setPrintEntryb");
          }
        })
      })
    },
    Cancel() {
      let pathname = '/' + window.location.pathname.split('/')[1]
      this.$router.push(pathname + "/examination/setPrintEntryb");
    },
    addClick(index) {
      let obj = {
        task: "任务1",
        xm: "",
        teachingClassName: "",
      }
      this.tablelist.splice(index + 1, 0, obj);
      for (const Key in this.tablelist) {
        this.tablelist[Key].task = '任务' + (parseInt(Key) + 1)
      }
    },

    deleteClick(index) {
      if (this.tablelist.length >= 2) {
        this.tablelist.splice(index, 1);
        for (const Key in this.tablelist) {
          this.tablelist[Key].task = '任务' + (parseInt(Key) + 1)
        }
      } else {
        this.$message.error('评价关系设置不能为空');
      }

    },
    ByAllRankAndGuide() {
      return new Promise(() => {
        ByAllRankAndGuide().then(res => {

          if (res.data.code === 200) {
            let data = res.data.data
            let arr = []
            for (const dataKey in data) {
              let obj = {...data[dataKey].pjEvalguide, ...data[dataKey].pjGuiderank}
              obj = {
                value: dataKey,//obj.guiderankoption
                label: obj.guidename,
                guideid:obj.guideid,
                //zhibiaoid  指标ID
                guiderankoption: obj.guiderankoption,
              }
              arr.push(obj)
            }
            this.systemList = arr
          }
        })
      })
    }
  },
};
</script>
<style lang="less" scoped>
.search-container {
  justify-content: flex-start !important;
}

.search-button {
  cursor: pointer;
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  width: 70px;
  height: 27px;
  background: #f1f8fe;
  border: 1px solid #51aef6;
  border-radius: 6px;

  > span {
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #51aef6;
  }

  > img {
    width: 19px;
    height: 19px;
    margin-right: 4px;
  }
}

.table-container {
  margin-top: 30px;

  .el-table td,
  .el-table th.is-leaf,
  .el-table--border,
  .el-table--group {
    border-color: #c7d7eb;
  }

  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 76px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }

  .el-table__body tr,
  .el-table__body td {
    padding: 0;
    height: 86px;
  }

  .wrapper-button {
    display: flex;
    flex-direction: column;
    align-items: center;

    > div {
      margin-bottom: 8px;
    }
  }
}
</style>

<style lang="less" scoped>
.item-row .el-col {
  display: flex;
  align-items: center;
  min-height: 60px;
  border-right: none !important;
}

.item-row .el-col:not(:first-child) {
  border-left: 1px solid rgba(0, 76, 167, 0.39);
}

.single-row .el-col:not(:last-child) {
  border-right: 1px solid rgba(0, 76, 167, 0.39);
}

.my-form .single-row:not(:last-child) {
  border-bottom: 1px solid rgba(0, 76, 167, 0.39);
}

.name-col {
  justify-content: center;
  font-size: 16px;
  font-weight: bold;
  color: #004ca7;
  background: rgba(77, 129, 192, 0.1);
}

.content-col {
  padding-left: 40px;
  color: #004ca7;
}

.wrapper-container {
  .my-form {
    width: 100%;
    border: 1px solid rgba(0, 76, 167, 0.8);
    margin: 57px auto 19px;
    border-radius: 9px;
  }
}

@import "../../../styles/special.less";
.bottom-block {
  padding-top: 30px;
  display: flex;
  flex-direction: row;
  justify-content: center;
}

.table-container ::v-deep .el-table--border .el-table__cell:first-child .cell {
  padding-left: 10px !important;
}

.filter-button1::v-deep .el-radio-button .el-radio-button__inner {
  border-radius: 6px !important;
  border: 1px solid rgb(245, 134, 106);
  color: rgb(245, 134, 106);
  background-color: rgb(254, 237, 226);
}

.filter-button1::v-deep
.el-radio-button__orig-radio:checked
+ .el-radio-button__inner {
  border: 1px solid rgb(245, 134, 106);
  color: white;
  background-color: rgb(245, 134, 106);
}

.filter-button {
  display: flex;
  margin-top: 27px;
}

.wrapper-container {
  width: 1711px;
  margin: 0 auto;
}

.table-container {
  margin-top: 30px;

  .table-data {
    margin-top: 10px;
    border: 0.8px solid #004ca7;
    border-radius: 9px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #004ca7;
  }
}

.save-button {
  width: 87px;
  height: 36px;
  line-height: 36px;
  background: #fff6ef;
  border: 1px solid #f3b815;
  border-radius: 6px;
  font-size: 18px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #f3b815;
  text-align: center;
  margin: 82px auto;
}

.zuoyou {
  width: 200px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
</style>
